<?php

class Admin_SalecategoryController extends Zend_Controller_Action
{

    public function init()
    {

        $this->_helper->layout->setLayout('admin/admin');

    }

    public function indexAction()
    {
        $params['page'] = $this->_getParam('page', 1);
        $params['limit'] = 10;
        $cache = Core_Global::getCache();
        $pages = ceil(count($cache->get('SaleCategory:ListIds')) / $params['limit']);
        $saleCategories = Model_SaleCategory::getAll($params);
        $this->view->assign('pages', $pages);
        $this->view->assign('SaleCategories', $saleCategories);
    }

    public function createAction()
    {
        $post = $this->_request->getPost();

        if ($post) {
            $result = Model_SaleCategory::create($post);
            $this->_helper->json($result);
        } else {
            $this->_helper->json(0);
        }

    }

    public function updateAction()
    {
        $post = $this->_request->getPost();
        if ($post) {
            $result = Model_SaleCategory::update($post);
            echo $this->_helper->json($result);
        } else
            echo $this->_helper->json(0);

    }

    public function deleteAction()
    {
        $catId = $this->_getParam('id');
        $result = Model_SaleCategory::delete($catId);
        echo $this->_helper->json($result);
    }


}